﻿using ProductMonitor.OpCommand;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProductMonitor.UserControls
{
    /// <summary>
    /// WorkShopDetailUC.xaml 的交互逻辑
    /// </summary>
    public partial class WorkShopDetailUC : UserControl
    {
        public WorkShopDetailUC()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 详情点击打开
        /// </summary>
        private void ShowColoumDetails()
        {
            detail.Visibility = Visibility.Visible;

            //设置动画(Animation)效果(由下而上)
            ThicknessAnimation thicknessAnimation = new ThicknessAnimation(new Thickness(0, 50, 0, -50),
                                                        new Thickness(0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 400));
            //设置透明度
            DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 0, 400));

            //添加属性到窗体之上
            Storyboard.SetTarget(thicknessAnimation, detailContent);
            Storyboard.SetTarget(doubleAnimation, detailContent);

            //指定动画效果作用的具体属性
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity"));

            //实例化
            Storyboard storyboard = new Storyboard();

            //将我们设置的动画都加入到“脚本”（集合了一系列的动画）中
            storyboard.Children.Add(thicknessAnimation);
            storyboard.Children.Add(doubleAnimation);
            storyboard.Begin();

        }

        /// <summary>
        /// 详情点击关闭
        /// </summary>
        private void CloseColoumDetails()
        {
            //设置动画(Animation)效果(由下而上)
            ThicknessAnimation thicknessAnimation = new ThicknessAnimation(new Thickness(0, 0, 0, 0), 
                                                    new Thickness(0, 300, 0, -300), new TimeSpan(0, 0, 0, 0, 400));
            //设置透明度
            DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 0, 400));

            //添加属性到窗体之上
            Storyboard.SetTarget(thicknessAnimation, detailContent);
            Storyboard.SetTarget(doubleAnimation, detailContent);

            //指定动画效果作用的具体属性
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity"));

            //实例化
            Storyboard storyboard = new Storyboard();

            //将我们设置的动画都加入到“脚本”（集合了一系列的动画）中
            storyboard.Children.Add(thicknessAnimation);
            storyboard.Children.Add(doubleAnimation);

            //动画完成事件订阅
            storyboard.Completed += (se, ev) =>
            {
                detail.Visibility = Visibility.Collapsed;
            };
            //不能忘记加
            storyboard.Begin();
        }

        //详情点击打开
        public Command ShowColoumDetailsCmd
        {
            get => new Command(ShowColoumDetails);
        }

        //详情点击关闭
        public Command CloseColoumDetailsCmd
        {
            get => new Command(CloseColoumDetails);
        }

    }
}
